partition.js ➔ ???   A
last analyzed

Complexity

Conditions 1
Paths 2

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 2
nop 2
dl 0
loc 20
rs 9.4285

1 Function

Rating   Name   Duplication   Size   Complexity  
A partition.js ➔ ... ➔ ??? 0 9 3
1
"use strict";
2
3
module.exports = (arr_, pred) => {
4
5
    const arr   = arr_ || [],
6
          spans = []
7
    
8
    let span = { label: undefined,
9
                 items: [arr.first] }
10
                 
11
    arr.forEach (x => {
12
13
        const label = pred (x)
14
15
        if ((span.label !== label) && span.items.length) {
16
            spans.push (span = { label: label, items: [x] }) }
17
18
        else {
19
            span.items.push (x) } })
20
21
    return spans
22
}